home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / www / thumbnail.lha / Thumbnail / thumbnail.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1998-09-10  |  8.7 KB  |  273 lines

  1. /* Taken from original script by Matthias Finger
  2.    Modified by Sébastien Boisvert for general use
  3.    Version 1.9 September 9 1998                       */
  4.  
  5. /* Options */
  6.  
  7. PATTERN = "~#?.(htm#?|info)"          /* file pattern to match/exclude (standard AmigaDOS patterns allowed) */
  8. BORDER=1                              /* border width for the table */
  9. GFXCON="work:images/gfxcon/GfxCon"    /* Path for GfxCON */
  10. FORMAT="gif"                          /* Format for destination picture (lower case!) uncomment next line for JPEG */
  11. /* FORMAT="jpeg" */
  12. QUALITY=85                /* Quality for jpeg destination     */
  13. VERBOSE=1                 /* GfxCon Verbose output: 1=OFF, 0=ON */
  14. BASE=''            /* Inserted in index file(s); put <BASE HREF=xxx> if you store your pictures elsewhere */
  15. PBASE=''            /* Inserted in picture page file(s); put <BASE HREF=xxx> if you store your pictures elsewhere */
  16. HEADER=''                 /* Header, inserted at top of page (after BODY tag) */
  17. FOOTER=''                 /* Footer, inserted at bottom of page (before /BODY tag) */
  18. PHEADER=''             /* Picture page Header, inserted at top of page (after BODY tag) */
  19. PFOOTER=''              /* Picture page Footer, inserted at bottom of page (before /BODY tag) */
  20.  
  21. sizex=100     /* default values for arguments */
  22. sizey=100
  23. dest="thumb"
  24. perpage=0
  25. res=800
  26. picpage=0
  27. /* ------- You should know what you do, if you change anything below -------- */
  28.  
  29. signal on error
  30. signal on BREAK_C
  31.  
  32. Say "Thumbnail 1.9  by Sébastien Boisvert"'0a'x
  33.  
  34. if ~show("L","rexxsupport.library") then
  35.   if ~ addlib("rexxsupport.library",0,-30,0) then do
  36.      say "Cannot open rexxsupport.library!"
  37.      exit 10
  38.      end
  39.      
  40. if ~show("L","rexxarplib.library") then
  41.   if ~addlib("rexxarplib.library",0,-30,2) then do
  42.      say "Need rexxarplib.library!"
  43.      exit 10
  44.      end
  45.      
  46. if ~show("L","rexxdossupport.library") then
  47.   if ~addlib("rexxdossupport.library",0,-30,0) then do
  48.      say "Need rexxdossupport.library!"
  49.      exit 10
  50.      end
  51.  
  52. template="SIZEX/N,SIZEY/N,DEST/K,PERPAGE/N,RES/N,PATTERN/K,PICPAGE/S"
  53.  
  54. parse arg args
  55. if arg(1)=="?" | ~Readargs(args,template) then signal usage     
  56.  
  57. /* put proper extensions on the format; remove 'E' form 'JPEG' */
  58. form="."||format
  59. form=compress(form,"e")
  60.  
  61. files=filelist(PATTERN,filenames,F,)  /* make file list */
  62.  
  63. if (files==0) then do
  64.   say "No files to process!"
  65.   exit 0
  66. end
  67.  
  68. if ~exists(dest) then 
  69.  call  makedir(dest)           /* check if directory exists and create it if not */
  70.  
  71. dest=dest||"/"
  72.  
  73. call sort()
  74. say "Checking for new pictures..."
  75.  
  76. do f=1 to files
  77.    name= filenames.f
  78.  
  79.   
  80.  call pragma("STACK",22000)
  81.  
  82.  parse var name file "." .
  83.  names.f="t_"||file||FORM
  84.  if ~exists(dest||names.f) then do    /* if thumbnail doesn't exists... */
  85.    comm = GFXCON||' "'||name'"'
  86.    IF(VERBOSE==1) THEN do
  87.      comm = comm||' >NIL:'
  88.      say "Processing file "name       /* make one */
  89.    end
  90.   comm = comm||' TO "'||dest||names.f||'" FORMAT 'FORMAT
  91.    IF (UPPER(FORM)==".JPG") THEN DO
  92.     comm = comm||' QUALITY 'QUALITY||' '
  93.    END
  94.   comm = comm||' BOXFIT '||sizex||' '||sizey
  95.   ADDRESS COMMAND comm             /* make up command line and execute it */
  96.  end 
  97.  if ~exists(dest||names.f) then say " Error - GfxCon could not create a thumbnail!"
  98. END
  99.  
  100. /* create thumbnail table */
  101.  
  102. if res="" then res=800  /* resolution; 800 for X default */
  103.  
  104. if perpage ==0 then perpage=files
  105.  
  106. number=1
  107. pagefiles=perpage
  108.  
  109. pages=files%perpage
  110. if files//perpage ~=0 then pages=pages+1
  111.  
  112. line="0a"x||"Creating "pages" index page"
  113. if pages>1 then line=line||"(s)"
  114. if picpage==1 then line=line||" and "files" picture pages"
  115. say line||"0a"x
  116.  
  117. do p=1 to pages
  118.  
  119. if files-(perpage*p)<0 then pagefiles=files//perpage
  120.  
  121. if pagefiles>0 then do
  122. max = res % ((border*2)+sizex+7)    /* get maximum number of thumbnails that fit on one row */
  123.  
  124. if (pagefiles//max) ~=0  then  do       /* if all thumbnails don't fit all equally */
  125.   mostremainders=pagefiles//max
  126.      do temp=max to 2 by -1                       /* figure out how many across will produce the least */
  127.         if pagefiles//temp > mostremainders then do   /* amount of blank spaces in last row */
  128.            mostremainders=pagefiles//temp
  129.            max=temp
  130.         end
  131.      end
  132. end
  133.  
  134. rows = pagefiles%max                    
  135. if pagefiles//max ~=0 then rows=rows+1
  136.  
  137. indexfile="output"
  138. if open(indexfile,"t_index"||p||".html","W") then do
  139. say "Creating index page #"||p||"..."                 /* Create the index page */
  140.  
  141.  call writeln(indexfile,"<HTML>")                 /* Put the code in */
  142.  call writeln(indexfile,"<BODY>")
  143.  call writeln(indexfile,BASE)
  144.  call writeln(indexfile,HEADER)
  145.  call writeln(indexfile,"<CENTER>"||"0a"x||"<BR>")
  146.  
  147.  line=''
  148.   do f=1 to pages
  149.      if f==p then
  150.         line=line||'<A HREF=t_index'||f||'.html><B>'||f||' </B></A>'
  151.      else
  152.         line=line||'<A HREF=t_index'||f||'.html>'||f||' </A>'
  153.   end
  154.   if pages>1 then call writeln(indexfile,line||"0a"x||"<BR>")
  155.  
  156.  call writeln(indexfile,"<TABLE BORDER="||border||">")
  157.  
  158. call pragma("STACK",22000)
  159.  
  160.  do rows                                           /* do the tables */
  161.  call writeln(indexfile,"<TR ALIGN=CENTER>")
  162.   do max
  163.      if number-(perpage*(p-1))>pagefiles then iterate
  164.      
  165.      comm=GFXCON||' >T:thumbinfo "'||dest||names.number||'" info'
  166.      fileinfo="fileinfo"
  167.      
  168.      address command comm
  169.      call open(fileinfo,"T:thumbinfo","r")
  170.      do 4
  171.        info=readln(fileinfo)
  172.      end
  173.      parse var info "input size: " thumbx "x" thumby .
  174.      call close(fileinfo)
  175.      if picpage then call writeln(indexfile,"   <TD><A HREF="||filenames.number||".html><IMG SRC="||dest||names.number||" ALT="||filenames.number||" WIDTH="||thumbx||" HEIGHT="||thumby||" BORDER=0></A></TD>")
  176.  else
  177.      call writeln(indexfile,"   <TD><A HREF="||filenames.number||"><IMG SRC="||dest||names.number||" ALT="||filenames.number||" WIDTH="||thumbx||" HEIGHT="||thumby||" BORDER=0></A></TD>")
  178.  
  179. if picpage then do     /* Create picture page */
  180.   line1=''
  181.      if open(picfile,filenames.number||".html","W") then do      /* Create picture page */
  182.         call writeln(picfile,"<HTML>")                 /* Put the code in */
  183.         call writeln(picfile,"<BODY>")
  184.         call writeln(picfile,PBASE)
  185.         call writeln(picfile,PHEADER)
  186.         call writeln(picfile,"<CENTER>"||"0a"x||"<BR>")
  187.         
  188.         comm=GFXCON||' >T:thumbinfo '||filenames.number||' info'
  189.         fileinfo="fileinfo"
  190.  
  191.         address command comm
  192.         call open(fileinfo,"T:thumbinfo","r")
  193.         do 4
  194.            info=readln(fileinfo)
  195.         end
  196.         parse var info "input size: " thumbx "x" thumby .
  197.         call close(fileinfo)
  198.         
  199.         call writeln(picfile,"<IMG SRC="||filenames.number||" WIDTH="||thumbx||" HEIGHT="||thumby||"><BR><PRE>") 
  200.  
  201.         prev=number-1; next=number+1
  202.         if number>1 then line1="<A HREF="filenames.prev||".html>Previous</A>   "
  203.         if number<files then line1=line1||'<A HREF='||filenames.next||'.html>Next</A>'
  204.         call writeln(picfile,line1||"<BR></PRE>")
  205.         call writeln(picfile,"Index: "||line)
  206.         call writeln(picfile,"</CENTER>")             /* close off the HTML document */    
  207.         call writeln(picfile,PFOOTER)
  208.         call writeln(picfile,"</BODY>")
  209.         call writeln(picfile,"</HTML>") 
  210.         call close (picfile)
  211.      end
  212.         else say "  Cannot create picture page file for "||filenames.number||"!"
  213.   end
  214.      number=number+1
  215.   end
  216.   call writeln(indexfile,"</TR>")
  217.  end
  218.  
  219.  call writeln(indexfile,"</TABLE>")
  220.  if pages>1 then call writeln(indexfile,line||"0a"x||"<BR>")
  221.  call writeln(indexfile,"</CENTER>")             /* close off the HTML document */
  222.  call writeln(indexfile,FOOTER)
  223.  call writeln(indexfile,"</BODY>")
  224.  call writeln(indexfile,"</HTML>")
  225.  call close (indexfile)
  226. end
  227. end
  228. else
  229.   say " Cannot create index file!!!"
  230. end
  231. call delete("T:thumbinfo")
  232. say "0a"x||"Done."
  233.  
  234. exit
  235.  
  236. /* Sort routine */
  237.  
  238. SORT: procedure expose filenames. files
  239. say "Sorting list of files..."
  240.  
  241. do f=1 to files-1
  242.   n=f+1
  243.   if filenames.f > filenames.n then
  244.      do
  245.      store=filenames.n
  246.      filenames.n=filenames.f
  247.      
  248.      do bubpos=f-1 to 1 by -1 while (store < filenames.bubpos)
  249.         n=bubpos+1
  250.         filenames.n=filenames.bubpos
  251.         end bubpos
  252.      
  253.      bubpos=bubpos+1
  254.      filenames.bubpos=store
  255.      end
  256. end f
  257. return
  258.  
  259. error:
  260. BREAK_C:
  261. if exists("T:thumbinfo") then call delete("T:thumbinfo")  /* clean up */
  262.    exit 5
  263.  
  264. usage:
  265. say "Usage: thumbnail SIZEX/N SIZEY/N DEST/K PERPAGE/N RES/N PATTERN/K PICPAGE/S"
  266. say "   SIZEX & SIZEY - maximum sizes for thumbnail ["SIZEX"] ["SIZEY"]"
  267. say "   DEST - directory to store thumbnails (no '/') ["DEST"]"
  268. say "   PERPAGE - the maximum number of pictures per table ["PERPAGE"]"
  269. say "   RES - intended page resolution ["RES"]"
  270. say "   PATTERN - standard AmigaDOS pattern used to match files ["PATTERN"]"
  271. say "   PICPAGE - if given will create an HTML page for each picture"
  272. exit
  273.